﻿using System;
using System.Collections.Generic;
using System.Linq;
using FollowMe.Model;

namespace FollowMe.Repository
{
    /// <summary>
    /// The Message Repo
    /// </summary>
    public class MessageRepository : Repository<Message, Guid>, IMessageRepository
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageRepository"/> class.
        /// </summary>
        /// <param name="fm">The fm.</param>
        public MessageRepository(IContext fm)
            : base(fm)
        { }

        /// <summary>
        /// Initializes a new instance of the <see cref="MessageRepository"/> class.
        /// </summary>
        public MessageRepository() { }

        /// <summary>
        /// Finds messages the user sent.
        /// </summary>
        /// <param name="Id">The member id.</param>
        /// <returns></returns>
        public IEnumerable<Message> FindISent(Guid Id)
        {
            return GetObjectSet().Where<Message>(m => m.MessageSenderId == Id);
        }

        /// <summary>
        /// Finds messages the user received
        /// </summary>
        /// <param name="Id">The member id.</param>
        /// <returns></returns>
        public IEnumerable<Message> FindIReceived(Guid Id)
        {
            return GetObjectSet().Where<Message>(m => m.MessageReceiverId == Id);
        }
    }
}
